<?php
class ModelAction extends BaseAction{
	
	  
    public function modelList(){
    	$this->assign("list",D('Model')->getModel());
    	$this->display();
    }
    public function getModel(){
    	
    	$model = D('Model')->getModelByTable($_GET['table']);
    	echo json_encode($model);
    }
    public function add(){
    	
    	$this->display();
    }
    
    public function doAdd(){
    	
    	$adObj = D('Model');
    	$ad = $adObj->where('tablename="'.$_POST['tablename'].'"')->find();
    	
    	if($ad){
    		$this->error('表已经存在！');
    	}else{
    		if($adObj->create()){
    			 if($adObj->add()){
    			 		S("site_model",null); //缓存清除
    			 		$this->assign("jumpUrl","__URL__/modelList");
    			 	  $this->success('添加成功！');
    			 }else{
    			 		$this->error('添加失败！');
    			 } 
    		}else{
    			$this->error($adObj->getError());
    		}
    		
     }
    	
   }
   
   public function edit(){
   	  $model = M('Model')->where('id='.$_GET['id'])->find();
   	  $this->assign("model",$model);
   	  $this->display();
   }
   
   public function doEdit(){
   	  $adObj = D('Model');
   	  if($adObj->create()){
   	  	if($adObj->save()){
   	  		S("site_model",null); //缓存清除
   	  		$this->assign("jumpUrl","__URL__/modelList");
   	  		$this->success('修改成功！');
   	  	}else{
   	  		$this->error('没用进行任何修改操作！');
   	  	}
   	  }else{
   	  	$this->error($adObj->getError());
   	  }
   	  
   }
   
   public function del(){
   	  $adObj = M('Model');
   	  $ad = $adObj->find($_GET['id']);
   	  if($ad){
   	  		$adx = $adObj->where('id='.$_GET['id'])->delete();
   	  }else{
   	  	
   	  	$this->error('您要删除的对象不存在！');
   	  }
   		
   		if($adx){
   			S("site_model",null); //缓存清除
   			$this->success('删除成功！');
   		}else{
   			$this->error('删除失败！');
   		}
   }
    
 
}
?>